import axiosRequest from "@/api/axiosRequest.ts";

/* 用户登录 */
const login = (loginData:{account?:string,email?:string, password:string}) => axiosRequest({
    url: '/login',
    method: 'POST',
    data: {
        account: loginData.account,
        email: loginData.email,
        password: loginData.password
    }
})

const loginByEmail = (loginData:{email:string, code:string}) => axiosRequest({
    url: '/loginByEmail',
    method: 'POST',
    data: {
        email: loginData.email,
        code: loginData.code
    }
})

/* 用户注册 */
const register = (user:RegisterParam) => axiosRequest({
    url: '/register',
    method: 'POST',
    data: user
})

const forgetPassword = (forgetPasswordData:{email:string, code:string, newPassword:string, confirmPassword:string}) => axiosRequest({
    url: '/forgetPassword',
    method: 'POST',
    data: forgetPasswordData
})

export const authApi = {
    login,
    loginByEmail,
    register,
    forgetPassword,
    sendMailCode : (email:string,  type?:number) => axiosRequest.get('/sendMailCode?email=' + email + (type?  '&type=' + type : ''))
}
